import { BasicColumn, FormSchema } from '@/components/Table/index';
const windowInstanse: any = window;

export const columns: BasicColumn[] = [
  {
    title: '账户',
    dataIndex: 'account',
    width: 150,
    align: 'center',
    sorter: true,
  },
  {
    title: '角色类型/角色描述',
    dataIndex: 'name1',
    width: 150,
    align: 'center',
    sorter: true,
    customRender: ({ record }) => {
      return `${record.roleName || ''} ${record.roleDescription ? ' / ' + record.roleDescription : ''}`;
    },
  },
  {
    title: '用户类型',
    dataIndex: 'userTypeCodeString',
    width: 150,
    align: 'center',
    sorter: true,
  },
  {
    title: '所属机构',
    dataIndex: 'code',
    width: 150,
    align: 'center',
    sorter: true,
    customRender: ({ record }) => {
      return `${record.fullOrganizationName || ''}`;
    },
  },
  {
    title: '是否启用',
    dataIndex: 'createdTime',
    width: 150,
    align: 'center',
    sorter: true,
    customRender: ({ record }) => {
      return record.isEnable ? '已启用' : '未启用';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createdTime',
    width: 150,
    align: 'center',
    sorter: true,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyWord',
    label: '关键字',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      placeholder: '请输入用户类型名称/编号',
    },
  },
  {
    field: 'organizationId',
    label: '所属机构',
    component: 'rwTreeSelect',
    colProps: { span: 6 },
    defaultValue: '',
    componentProps: {
      type: 'org',
      placeholder: '请选择机构',
    },
  },
  {
    label: '角色类型',
    field: 'RoleTypeCode',
    colProps: { span: 6 },
    component: 'dictSelect',
    componentProps: {
      placeholder: '请选择角色对象类型',
      code: 'ROLE_TYPE',
    },
  },
];

export const editPasswordSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'oldPassword',
    label: '原密码',
    component: 'StrengthMeter',
    required: true,
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'newPassword',
    label: '新密码',
    component: 'StrengthMeter',
    required: true,
    colProps: { lg: 24, md: 24 },
  },
];
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'account',
    label: '用户名',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入用户名（必填）',
    },
  },
  {
    field: 'code',
    label: '用户编号',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入用户编号（必填）',
    },
  },
  {
    field: 'password',
    label: '密码',
    required: true,
    component: 'InputPassword',
    ifShow: (formModel) => {
      return !formModel.model.id;
    },
    componentProps: {
      placeholder: '请输入登录密码（必填）',
      type: 'password'
    },
  },
  {
    field: 'organizationId',
    label: '所属机构',
    required: true,
    component: 'rwTreeSelect',
    defaultValue: '',
    ifShow: (formModel) => {
      return formModel.model.organizationId != '0';
    },
    componentProps: ({ formModel }) => {
      return {
        type: 'org',
        value: formModel.organizationId,
        parentId: '0',
        onChange: () => {
          formModel.a = '';
        },
      };
    },
  },
  // {
  //   field: 'departmentId',
  //   label: '所属部门',
  //   component: 'rwTreeSelect',
  //   defaultValue: "",
  //   componentProps: ({ formModel }) => {
  //     return {
  //       type: 'org',
  //       watchParams: 'parentId',
  //       placeholder: "请选择所属部门"
  //     }
  //   }
  // },
  {
    field: 'roleId',
    label: '用户角色',
    required: true,
    component: 'rwSelect',
    ifShow: (formModel) => {
      return formModel.model.organizationId != '0';
    },
    componentProps: ({ formModel }) => {
      return {
        type: 'role',
        watchParams: 'organizationId',
        xhrParams: {
          organizationId: formModel.organizationId || '0',
        },
      };
    },
  },
  {
    field: 'userTypeCode',
    label: '用户类型',
    component: 'dictSelect',
    ifShow: (formModel) => {
      return formModel.model.organizationId != '0';
    },
    componentProps: {
      code: 'USER_TYPE',
      placeholder: '请选择用户类型',
    },
  },
  {
    field: 'name',
    label: '用户姓名',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入用户姓名',
    },
  },
  {
    field: 'sex',
    label: '性别',
    component: 'dictSelect',
    colProps: { span: 12 },
    required: true,
    componentProps: {
      code: 'SEX',
      placeholder: '请选择性别',
    },
  },
  {
    field: 'phoneNumber',
    label: '手机号码',
    component: 'Input',
    componentProps: {
      placeholder: '请输入手机号码（可用于后续重置密码验证）',
    },
  },
  {
    field: 'email',
    label: '邮箱地址',
    component: 'Input',
    componentProps: {
      placeholder: '请输入邮箱地址（可用于后续重置密码验证）',
    },
  },
  {
    field: 'birthday',
    label: '出生日期',
    component: 'DatePicker',
    componentProps: {
      placeholder: '请输入出生日期',
    },
  },

  {
    field: 'weiXin',
    label: '微信号',
    component: 'Input',
    componentProps: {
      placeholder: '请输入微信号（非必填）',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    colProps: { lg: 24, md: 24 },
    componentProps: {
      placeholder: '请输入备注',
    },
  },

  {
    field: 'avatarUrl',
    label: '头像',
    colProps: { span: 24 },
    component: 'RwUpload',
    componentProps: {
      base_url: windowInstanse.config.base_url,
    },
  },
  {
    field: 'isEnable',
    label: '允许登录',
    component: 'Switch',
    defaultValue: true,
    colProps: { lg: 24, md: 24 },
  },
];
